Kernel.module.define('navigation', {
	
	title: 'navigation',
	//file: 'navigation.php',
	widget: true,
	EARTH_RADIUS: 6378137,
	DEG_TO_RAD_FACTOR: Math.PI / 180,
	
	init: function() {
		var module = this;

		var map = new ol.Map({
			target: 'dashNavigationLyr',
			layers: [
				new ol.layer.Tile({
					source: new ol.source.XYZ({
						url: 'http://localhost:8080/osm/{z}/{x}/{y}.png',
						minZoom: 1,
						maxZoom: 18,
						wrapX: false
					})
				})
			],
			view: new ol.View({
				center: ol.proj.fromLonLat([145.143163, -37.786989]),
//				rotation: Math.PI / 6,
				zoom: 17
			}),
			controls: ol.control.defaults().extend([
				new ol.control.ScaleLine()
			])
			
		});
		
		map.on('click', function(e) {
			var lonlat = ol.proj.transform(e.coordinate, 'EPSG:3857', 'EPSG:4326');
			lp = [[145.147038, -37.791723]];

			var destLocationLat = lonlat[1];
			var destLocationLng = lonlat[0];
			
			var routeURL = "?point=-37.791723%2C145.147038&point="+destLocationLat+"%2C"+destLocationLng+"&locale=en-GB&vehicle=car&weighting=fastest&elevation=false&layer=Omniscale&points_encoded=false"
			$.get('http://localhost:8989/route/'+routeURL, function(data) {
				lpCount = data.paths[0].points.coordinates.length;

				for (i = 0; i < lpCount; i++) {
					lp = lp.concat([[data.paths[0].points.coordinates[i][0], data.paths[0].points.coordinates[i][1]]]);
					
				}
				
//				if (typeof line !== 'undefined') {
//					map.removeLayer(line);
//				}
				
				navMode = 1;
			});
			
			

		})

//		map.getView().setCenter(ol.proj.transform([-37.786989,145.143163], 'EPSG:4326', 'EPSG:3857'));
//		var v2D = map.getView().getView2D();
//		var currentR = map.getView().getView2D.getRotation();
//		v2D.setRotation(currentRad+1.5);
	},
	
	resizedone: function(map) {
	}
});
